//const { timePanelSharedProps } = require("element-plus/es/components/time-picker/src/props/shared")
module.exports = (sequelize, DataTypes) => {
    const user = sequelize.import('./user.model')
    const employee = sequelize.import('./employee.model')
    const loginModel = sequelize.define('login', {
        uid:{
            type:DataTypes.INTEGER,
            allowNull:false,
            // autoIncrement: true,
        },
        user_name: {
            type: DataTypes.STRING,
            allowNull: false,
            primaryKey: true,
        },
        pwd: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        times: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue:0
        },
        status: {
            type: DataTypes.ENUM('离线', '在线'),
            allowNull: false,
            defaultValue:'离线'
        },
        createdAt: {
            type: DataTypes.DATE,
            allowNull: false
        },
        updatedAt: {
            type: DataTypes.DATE,
            allowNull: false
        }},{
            tableName: 'login'
        });
    loginModel.belongsTo(user,{
        foreignKey: 'uid',
        sourceKey: 'uid',
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE'
    })
    user.hasOne(loginModel,{
        foreignKey: 'uid',
        sourceKey: 'uid',
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE'
    })
    loginModel.hasOne(employee, {
        foreignKey: 'uid',
        sourceKey: 'uid',
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE'
    })

    // loginModel.beforeCreate(async (login) => {
    //     await user.create({identity:'普通用户'})
    // })
    // loginModel.afterCreate(async (login)=>{
    //     await user.update({
    //         uid:login.uid
    //     })
    // })


    loginModel.beforeDestroy(async (login) => {
        await user.destroy({
            where: {
                uid: login.uid
            }
        })
    })
    return loginModel
}

